<template>
    <sc-dialog v-model="visible" title="提现审批" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="right">
            <el-form-item label="部门" prop="department.title">
                {{ withdrawal.department.title }}
            </el-form-item>
            <el-form-item label="提现金额" prop="amount">
                {{ withdrawal.amount }}
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                {{ withdrawal.remark || '无' }}
            </el-form-item>
            <el-form-item label="提现时间" prop="create_at">
                {{ withdrawal.create_at }}
            </el-form-item>
            <el-form-item label="审批" prop="status">
                <el-radio-group v-model="form.status">
                    <!-- works when <2.6.0, deprecated act as value when >=3.0.0 -->
                    <el-radio :label="10">通过</el-radio>
                    <el-radio :label="2">不通过</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="拒绝原因" prop="reject_reason" v-if="form.status == 2">
                <el-input type="textarea" :row="3" v-model="form.reject_reason" clearable></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button type="primary" :loading="isSaveing" @click="submit()">确认</el-button>
        </template>
    </sc-dialog>
</template>

<script>
export default {
    emits: ['success', 'closed'],
    data () {
        return {
            visible: true,
            isSaveing: false,
            withdrawal: {
                department: {}
            },
            form: {
                status: 10
            },
            //验证规则
            rules: {
                status: [
                    { required: true, message: '请选择审批是否通过', trigger: 'change' }
                ],
                reject_reason: [
                    { required: true, message: '请填写拒绝原因', trigger: 'change' }
                ],
            }
        }
    },
    mounted () {

    },
    methods: {
        open () {
            this.visible = true;
            return this;
        },
        setData (data) {
            this.withdrawal = data
        },
        submit () {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    this.$API.app.withdrawal.approval.post(this.withdrawal.id, this.form)
                        .then((res) => {
                            this.isSaveing = false
                            this.$message.success(res.message)
                            this.visible = false;
                            this.$emit('success')
                        })
                        .catch(() => {
                            this.isSaveing = false
                        })
                }
            })
        }
    }
}
</script>

<style></style>
